package com.anxinr.execute;

import com.anxinr.config.ExecutorConfig;
import com.anxinr.exception.MyFrameException;
import com.anxinr.frame.MyTaskThreadPoolExecutor;
import com.anxinr.function.LambdaInterface;

import java.util.Objects;
import java.util.concurrent.ArrayBlockingQueue;

/**
 * 线程使用工具类
 * @author : anxinr
 * @date : 2022/10/12 13:30
 */
public class ThreadPoolExecute implements LambdaInterface {
    /**执行类的对象*/
    public static ThreadPoolExecute execute ;
    /**我的线程池框架对象*/
    private static MyTaskThreadPoolExecutor taskThreadPoolExecutor ;



    /**
     * 获取线程框架对象
     * @return MyTaskThreadPoolExecutor
     */
    public ThreadPoolExecute getInstance(Integer maxTaskNumber,Integer coreThread) throws Exception {
        taskThreadPoolExecutor = MyTaskThreadPoolExecutor.getInstance(maxTaskNumber,coreThread) ;
        execute = new ThreadPoolExecute() ;
        return execute ;
    }
    /**
     * 获取线程框架对象
     * @return MyTaskThreadPoolExecutor
     */
    public static ThreadPoolExecute getInstance() {
        taskThreadPoolExecutor = MyTaskThreadPoolExecutor.getInstance() ;
        execute = new ThreadPoolExecute() ;
        return execute ;
    }

    @Override
    public void execute(Runnable thread) {
        taskThreadPoolExecutor.addTaskToQueue(thread);
    }
}
